home *** CD-ROM | disk | FTP | other *** search
/ Programming in Microsoft Windows with C# / Programacion en Microsoft Windows con C#.iso / Original Code / Buttons and Labels and Scrolls (Oh, My!) / TwoButtonsAnchor / TwoButtonsAnchor.cs next >
Encoding:
Text File  |  2001-01-15  |  1.8 KB  |  54 lines

  1. //-----------------------------------------------
  2. // TwoButtonsAnchor.cs ⌐ 2001 by Charles Petzold
  3. //-----------------------------------------------
  4. using System;
  5. using System.Drawing;
  6. using System.Windows.Forms;
  7.  
  8. class TwoButtonsAnchor: Form
  9. {
  10.      public static void Main()
  11.      {
  12.           Application.Run(new TwoButtonsAnchor());
  13.      }
  14.      public TwoButtonsAnchor()
  15.      {
  16.           Text = "Two Buttons with Anchor";
  17.           ResizeRedraw = true;
  18.  
  19.           int cxBtn = 5 * Font.Height;
  20.           int cyBtn = 2 * Font.Height;
  21.           int dxBtn =     Font.Height;
  22.  
  23.           Button btn = new Button();
  24.           btn.Parent   = this;
  25.           btn.Text     = "&Larger";
  26.           btn.Location = new Point(dxBtn, dxBtn);
  27.           btn.Size     = new Size(cxBtn, cyBtn);
  28.           btn.Click   += new EventHandler(ButtonLargerOnClick);
  29.           
  30.           btn = new Button();
  31.           btn.Parent   = this;
  32.           btn.Text     = "&Smaller";
  33.           btn.Location = new Point(ClientSize.Width  - cxBtn - dxBtn,
  34.                                    ClientSize.Height - cyBtn - dxBtn);
  35.           btn.Size     = new Size(cxBtn, cyBtn);
  36.           btn.Anchor   = AnchorStyles.Right | AnchorStyles.Bottom;
  37.           btn.Click   += new EventHandler(ButtonSmallerOnClick);
  38.      }
  39.      void ButtonLargerOnClick(object obj, EventArgs ea)
  40.      {
  41.           Left   -= (int)(0.05 * Width);
  42.           Top    -= (int)(0.05 * Height);
  43.           Width  += (int)(0.10 * Width);
  44.           Height += (int)(0.10 * Height);
  45.      }
  46.      void ButtonSmallerOnClick(object obj, EventArgs ea)
  47.      {
  48.           Left   += (int)(Width  / 22f);
  49.           Top    += (int)(Height / 22f);
  50.           Width  -= (int)(Width  / 11f);
  51.           Height -= (int)(Height / 11f);
  52.      }
  53. }
  54.